import type * as Auth from "./type"
import { request } from "@/http/axios"

/** 获取登录验证码 */
export function getCaptchaApi() {
  return request<Auth.CaptchaResponseData>({
    url: "auth/captcha",
    method: "get"
  })
}

/** 刷新验证码 */
export function refreshCaptchaApi(captchaId?: string) {
  return request<Auth.CaptchaResponseData>({
    url: "auth/captcha/refresh",
    method: "post",
    params: { captchaId }
  })
}

/** 验证验证码 */
export function validateCaptchaApi(captchaId: string, captchaCode: string) {
  return request<ApiResponseData<boolean>>({
    url: "auth/captcha/validate",
    method: "post",
    params: { captchaId, captchaCode }
  })
}

/** 登录并返回 Token */
export function loginApi(data: Auth.LoginRequestData) {
  return request<Auth.LoginResponseData>({
    url: "auth/login",
    method: "post",
    data
  })
}

/** 刷新Token */
export function refreshTokenApi(refreshToken: string) {
  return request<Auth.LoginResponseData>({
    url: "auth/refresh",
    method: "post",
    data: { refreshToken }
  })
}

/** 退出登录 */
export function logoutApi() {
  return request<void>({
    url: "auth/logout",
    method: "post"
  })
}

/** 获取当前用户信息 */
export function getCurrentUserApi() {
  return request<Auth.UserInfoResponseData>({
    url: "auth/currentUser",
    method: "get"
  })
}
